#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
控制面板模块
负责创建和管理控制面板的UI组件
"""

from PySide6.QtWidgets import QPushButton, QHBoxLayout, QGroupBox
from src.config import Config


class ControlPanel:
    """控制面板类"""
    
    def __init__(self):
        """初始化控制面板"""
        # 按钮组件
        self.import_button = None
        self.switch_video_button = None  # 切换视频按钮
        self.play_pause_button = None
        self.skip_to_start_button = None
        self.step_backward_button = None
        self.step_forward_button = None
        self.skip_to_end_button = None
        self.mark_in_button = None
        self.mark_out_button = None
        self.export_button = None
        
    def create_control_panel(self, parent_layout):
        """
        创建控制面板
        
        创建包含视频播放控制和片段标记按钮的控制面板。控制面板使用水平布局，
        包含三组功能按钮：
        1. 视频操作按钮：导入视频
        2. 播放控制按钮：播放/暂停、跳转、步进
        3. 片段标记按钮：标记入点、出点、导出视频
        
        Args:
            parent_layout (QVBoxLayout): 父布局管理器，用于添加控制面板组件
            
        Returns:
            tuple: 包含所有创建的按钮组件
        """
        control_group = QGroupBox(Config.CONTROL_GROUP_TITLE)
        control_layout = QHBoxLayout(control_group)
        
        # 导入视频按钮
        self.import_button = QPushButton(Config.IMPORT_BUTTON_TEXT)
        control_layout.addWidget(self.import_button)
        
        # 切换视频按钮（初始隐藏）
        self.switch_video_button = QPushButton("切换视频")
        self.switch_video_button.setVisible(False)  # 初始隐藏
        control_layout.addWidget(self.switch_video_button)
        
        # 播放/暂停按钮
        self.play_pause_button = QPushButton(Config.PLAY_BUTTON_TEXT)
        control_layout.addWidget(self.play_pause_button)
        
        # 跳转到开始按钮
        self.skip_to_start_button = QPushButton(Config.SKIP_TO_START_TEXT)
        control_layout.addWidget(self.skip_to_start_button)
        
        # 后退一帧按钮
        self.step_backward_button = QPushButton(Config.STEP_BACKWARD_TEXT)
        control_layout.addWidget(self.step_backward_button)
        
        # 前进一帧按钮
        self.step_forward_button = QPushButton(Config.STEP_FORWARD_TEXT)
        control_layout.addWidget(self.step_forward_button)
        
        # 跳转到结束按钮
        self.skip_to_end_button = QPushButton(Config.SKIP_TO_END_TEXT)
        control_layout.addWidget(self.skip_to_end_button)
        
        # 标记入点按钮
        self.mark_in_button = QPushButton(Config.MARK_IN_BUTTON_TEXT)
        control_layout.addWidget(self.mark_in_button)
        
        # 标记出点按钮
        self.mark_out_button = QPushButton(Config.MARK_OUT_BUTTON_TEXT)
        control_layout.addWidget(self.mark_out_button)
        
        # 导出/合并按钮
        self.export_button = QPushButton(Config.EXPORT_BUTTON_TEXT)
        control_layout.addWidget(self.export_button)
        
        parent_layout.addWidget(control_group)
        
        return (
            control_group,
            self.import_button,
            self.switch_video_button,
            self.play_pause_button,
            self.skip_to_start_button,
            self.step_backward_button,
            self.step_forward_button,
            self.skip_to_end_button,
            self.mark_in_button,
            self.mark_out_button,
            self.export_button
        )